#include "Window.h"
#include "Color.h"
#include "Shader.h"
#include "Program.h"
#include "VertexBuffer.h"
#include "BufferBindingList.h"
#include "Layouts.h"
#include "Enums.h"
#include "Mesh.h"
#include "Texture.h"
#include "Vertex.h"
#include "BackBufferDrawAction.h"


struct Vert
{
	float x,y,z;
	float s,t;
	Vert(float _x,float _y,float _z,float _s,float _t)
	{
		x = _x;
		y = _y;
		z = _z;
		s = _s;
		t = _t;
	}
	Vert()
	{

	}
};

int main()
{
	Window window(600,600,"title");
	window.Init();

	Pos_TCoord_Vertex * v = new Pos_TCoord_Vertex[6];
	v[0] = Pos_TCoord_Vertex(-1.0f,-1.0f,0.0f,0.0f,1.0f);
	v[1] = Pos_TCoord_Vertex(-1.0f,1.0f,0.0f,0.0f,0.0f);
	v[2] = Pos_TCoord_Vertex(1.0f,-1.0f,0.0f,1.0f,1.0f);
	v[3] = Pos_TCoord_Vertex(-1.0f,1.0f,0.0f,0.0f,0.0f);
	v[4] = Pos_TCoord_Vertex(1.0f,1.0f,0.0f,1.0f,0.0f);
	v[5] = Pos_TCoord_Vertex(1.0f,-1.0f,0.0f,1.0f,1.0f);

	Pos_TCord_Layout layout;

	Pos_Vertex vers(1.0f,1.0f,1.0f);

	Mesh mesh;
	mesh.BeginSetUp();
	mesh.SetVertexData(v,120,6,STATIC);
	mesh.SetLayout(&layout);
	mesh.EndSetUp();

	Shader vShader(VERTEX);
	vShader.LoadFromFile("vert.txt");
	vShader.Compile();

	Shader fShader(PIXEL);
	fShader.LoadFromFile("frag.txt");
	fShader.Compile("#define COLOR \n\0");

	Program progr;
	progr.AttachShader(vShader.GetGLShader());
	progr.AttachShader(fShader.GetGLShader());

	progr.LinkShaders();
	progr.Bind();


	Texture tex;
	Texture::SetActiveSlot(0);
	tex.Bind();
	tex.LoadFromFile("img.bmp");
	tex.SetProperty(WRAP_S,REPEAT);
	tex.SetProperty(WRAP_T,REPEAT);
	tex.SetProperty(MIN_FILTER,LINEAR);
	tex.SetProperty(MAG_FILTER,LINEAR);
	tex.GerateMipMaps();
	int loc = progr.GetUniformLocation("diffuse");

	Texture tex1;
	Texture::SetActiveSlot(1);
	tex1.Bind();
	tex1.LoadFromFile("lion.jpg");
	tex1.SetProperty(WRAP_S,REPEAT);
	tex1.SetProperty(WRAP_T,REPEAT);
	tex1.SetProperty(MIN_FILTER,LINEAR);
	tex1.SetProperty(MAG_FILTER,LINEAR);
	tex1.GerateMipMaps();

	int loc2 = progr.GetUniformLocation("lion");

	BackBufferDrawAction drawAction;
	drawAction.BindBackBuffer();
	drawAction.SetClearColor(Color(0.0f,0.0f,0.0f,1.0f));
	drawAction.SetClearTargets(COLOR_TARGET|DEPTH_TARGET);
	drawAction.UseDepthTest(true);

	while(!window.Closed())
	{
		Texture::BindUniformToSlot(loc,0);
		Texture::BindUniformToSlot(loc2,1);

		drawAction.Clear();

		mesh.Draw();

		window.Present();
	}

	return 0;
}